package com.ruoyi;

import org.junit.Test;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class test1 {

    @Test
    public void test(){
        try {
            Date date = new Date();
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            cal.set(Calendar.DAY_OF_MONTH, 2);
            cal.roll(Calendar.DAY_OF_MONTH, -1);
            System.out.println("----------");
            System.out.println(cal.getTime());
            System.out.println("----------"+new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime()));

            Calendar c=Calendar.getInstance();
            DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
            c.add(Calendar.DAY_OF_WEEK,(-1)*c.get(Calendar.DAY_OF_WEEK)+2);
            System.out.println("本周第一天："+df.format(c.getTime()));
            c.add(Calendar.DAY_OF_WEEK,8-c.get(Calendar.DAY_OF_WEEK));
            System.out.println("本周最后一天："+df.format(c.getTime()));

        }catch (Exception e){

        }
    }

}
